package com.ht.controller;

import com.ht.data.Result;
import com.ht.domain.bo.PopularizationBO;
import com.ht.domain.po.TbPopularization;
import com.ht.dto.TbPopularizationDTO;
import com.ht.service.PopularizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("popularizationController")
@Api
@RefreshScope
public class PopularizationController {

    @Autowired
    private PopularizationService popularizationService;

    /**
     * 添加科普号并绑定医生id
     * @param doctorId
     * @param popularizationDTO
     * @return
     */
    @ApiOperation("添加科普号并绑定医生id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId",value = "医生id",required = true,paramType = "path",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "popularizationDTO",value = "科普号实体",required = true,paramType = "body",dataTypeClass = TbPopularizationDTO.class)
    })
    @PostMapping("addPopularization/{doctorId}")
    public Result addPopularization(@PathVariable("doctorId")Long doctorId,@RequestBody TbPopularizationDTO popularizationDTO){
        PopularizationBO popularizationBO = new PopularizationBO();
        BeanUtils.copyProperties(popularizationDTO,popularizationBO);
        int i = popularizationService.addPopularization(doctorId,popularizationBO);
        if (i <= 0){
            return Result.ERROR();
        }
        return Result.OK();
    }


}
